using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Sec_scan漏洞扫描系统
{
    public partial class A_Sec_Scan_Start : Form
    {
        private Process p = new Process();
        Sec_Scan_Scan b = null;//接收窗体
        public A_Sec_Scan_Start()
        {
            InitializeComponent();
            b = new Sec_Scan_Scan();//实例化b窗体
            b.MyEvent += new Sec_Scan_Scan.MyDelegate(b_MyEvent);//监听b窗体事件
            StartPosition = FormStartPosition.CenterScreen;
            //系统主页
            OpenForm(new Sec_Scan_HomePage());
        }
        void b_MyEvent()
        {
            timer1.Start();
        }
        /// <summary>
        /// 隐藏或设置窗体，应用于选项卡
        /// </summary>
        /// <param name="subForm"></param>
        public void OpenForm(Form subForm)
        {
            foreach (Control item in this.panel3.Controls)
            {
                if (item is Form)
                {
                    ((Form)item).Close();
                }
            }
            subForm.TopLevel = false;// 将子窗体设置为非顶级控件
            subForm.FormBorderStyle = FormBorderStyle.None;//设置无边框
            subForm.Parent = this.panel3;//设置窗体容器
            subForm.Dock = DockStyle.Fill; //容器大小随着调整窗体大小自动变化
            subForm.Show();
        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void linkLabel8_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }
        public int oldX, oldY;
        private void panel2_MouseDown(object sender, MouseEventArgs e)
        {
            //判断是否为鼠标左键
            if (e.Button == MouseButtons.Left)
            {
                //获取鼠标左键按下时的位置
                this.oldX = e.Location.X;
                this.oldY = e.Location.Y;
            }
        }

        private void pictureBox11_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void label1_Click(object sender, EventArgs e)
        {
            //刷新颜色
            ReferBackColor();
            panel4.BackColor = Color.Navy;
            //创建漏洞扫描
            //OpenForm(new Scan());
            b.StartPosition = FormStartPosition.CenterScreen;
            b.ShowDialog();
        }

        private void label2_Click(object sender, EventArgs e)
        {
            //刷新颜色
            ReferBackColor();
            panel5.BackColor = Color.Navy;
            //系统主页
            OpenForm(new Sec_Scan_HomePage());
        }

        private void Start_Load(object sender, EventArgs e)
        {
            panel5.BackColor = Color.Navy;
            //系统主页
            OpenForm(new Sec_Scan_HomePage());
        }

        private void panel2_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                //计算鼠标移动距离
                this.Left += e.Location.X - this.oldX;
                this.Top += e.Location.Y - this.oldY;
            }
        }

        private void label3_Click(object sender, EventArgs e)
        {
            //刷新颜色
            ReferBackColor();
            panel6.BackColor = Color.Navy;
            //压力测试
            OpenForm(new Sec_Scan_Pressure());
        }
        private void label4_Click(object sender, EventArgs e)
        {
            //刷新颜色
            ReferBackColor();
            panel7.BackColor = Color.Navy;
            //帮助中心
        }

        private void label5_Click(object sender, EventArgs e)
        {
            //刷新颜色
            MessageBox.Show("该项功能暂未开发！");
            return;
            ReferBackColor();
            panel8.BackColor = Color.Navy;
            //后台扫描
            OpenForm(new Sec_Scan_Scan1());
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void label6_Click(object sender, EventArgs e)
        {
            //刷新颜色
            ReferBackColor();
            panel9.BackColor = Color.Navy;
            Sec_Scan_AddProject add = new Sec_Scan_AddProject();
            add.StartPosition = FormStartPosition.CenterScreen;
            add.ShowDialog();
        }

        private void label7_Click(object sender, EventArgs e)
        {
            //刷新颜色
            ReferBackColor();
            panel10.BackColor = Color.Navy;
            OpenForm(new Sec_Scan_SystemSet());
        }

        private void label8_Click(object sender, EventArgs e)
        {
            //刷新颜色 集成工具
            ReferBackColor();
            panel11.BackColor = Color.Navy;
            OpenForm(new Sec_InterGration_ScanTools());
        }

        public void timer1_Tick(object sender, EventArgs e)
        {
            if(timer1.Enabled == true)
            {
                timer1.Enabled = false;
                timer1.Stop();
                OpenForm(new Sec_Scan_AddScan());
            }
        }

        private void label9_Click(object sender, EventArgs e)
        {
            //刷新颜色
            ReferBackColor();
            panel12.BackColor = Color.Navy;
            OpenForm(new Sec_Scan_LoopList());
        }

        /// <summary>
        /// 刷新背景颜色
        /// </summary>
        public void ReferBackColor()
        {
            panel1.BackColor = Color.DeepSkyBlue;
            panel4.BackColor = Color.DeepSkyBlue;
            panel5.BackColor = Color.DeepSkyBlue;
            panel6.BackColor = Color.DeepSkyBlue;
            panel7.BackColor = Color.DeepSkyBlue;
            panel8.BackColor = Color.DeepSkyBlue;
            panel9.BackColor = Color.DeepSkyBlue;
            panel10.BackColor = Color.DeepSkyBlue;
            panel11.BackColor = Color.DeepSkyBlue;
            panel12.BackColor = Color.DeepSkyBlue;
        }
    }
}
